package com.baizhi.springboot.service.impl;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.baizhi.springboot.dao.LogDao;
import com.baizhi.springboot.entity.Album;
import com.baizhi.springboot.entity.Log;
import com.baizhi.springboot.service.LogService;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogDao logDao;
    @Override
    public Map selectLogByPage(Integer page, Integer limit,String content,String type) {
        Integer offset=(page-1)*limit;
        List<Log> Logs = logDao.selectLogByPage(offset, limit,content,type);
        Integer count = logDao.selectCount(content,type);
        List<String> typeList= logDao.selectAllType();
        /* "code": 0,
          "msg": "",
          "count": 1000,
          "data": [{}, {}]*/
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", Logs);
        map.put("typeList", typeList);
        return map;
    }

    @Override
    public void deleteLogMany(Integer[] ids) {
        logDao.deleteLogMany(ids);
    }

    @Override
    public HSSFWorkbook daochuAllLog() {
        /*ExportParams params = new ExportParams("用户信息展示","sheet", ExcelType.HSSF);
        List<User> users = userDao.selectAllUser();
        return (HSSFWorkbook) ExcelExportUtil.exportExcel(params, User.class, users);*/
        List<Log> list=logDao.selectAllLog();
        ExportParams exportparams=new ExportParams("日志信息展示","sheet",ExcelType.HSSF);
        return (HSSFWorkbook) ExcelExportUtil.exportExcel(exportparams, Log.class, list);
    }

    @Override
    public void insertLog(Log log) {
        logDao.insertLog(log);
    }
}
